﻿Imports Microsoft.Xna.Framework.GamerServices
Imports Microsoft.Xna.Framework.Graphics
Imports Microsoft.Xna.Framework

Public Class NotificationMessage

#Region " Fields "
    Private mGameManager As GameManager
    Private mMessage As String
    Private mFadeInTime As Single
    Private mOnScreenTime As Single
    Private mFadeOutTime As Single
    Private mPosition As NotificationPosition
    Private mCallBack As SimpleCallback
    Private mTimeSoFar As Single
#End Region ' Fields

#Region " Properties "

    Public ReadOnly Property GameManager() As GameManager
        Get
            GameManager = mGameManager
        End Get
    End Property

    Public ReadOnly Property Message() As String
        Get
            Message = mMessage
        End Get
    End Property

    Public ReadOnly Property OnScreenTime() As Single
        Get
            OnScreenTime = mOnScreenTime
        End Get
    End Property

    Public ReadOnly Property Position() As NotificationPosition
        Get
            Position = mPosition
        End Get
    End Property

    Public ReadOnly Property TimeSoFar() As Single
        Get
            TimeSoFar = mTimeSoFar
        End Get
    End Property

#End Region ' Properties

    Public Sub New(ByVal gameManager As GameManager, ByVal message As String, ByVal onScreenTime As Single, ByVal positionOnScreen As NotificationPosition, ByVal callBack As SimpleCallback, ByVal fadeInTime As Single, ByVal fadeOutTime As Single)
        mGameManager = gameManager
        mMessage = message
        mFadeInTime = fadeInTime
        mOnScreenTime = onScreenTime
        mFadeOutTime = fadeOutTime
        mPosition = positionOnScreen
        mCallBack = callBack
    End Sub

    Public Sub New(ByVal gameManager As GameManager, ByVal message As String, ByVal callBack As SimpleCallback)
        MyClass.New(gameManager, message, 1.3F, NotificationPosition.Center, callBack, 0.1F, 0.1F)
    End Sub

    Public Overridable Sub Update(ByVal elapsedSeconds As Single)
        mTimeSoFar += elapsedSeconds
        If mTimeSoFar >= mOnScreenTime Then mCallBack.Invoke()
    End Sub

    Public Overridable Sub Draw(ByVal elapsedSeconds As Single)
        ' Message will appear in centre of screen
        Dim size As Vector2 = GameManager.Font.MeasureString(Message)
        Dim pos1 As New Vector2((GameManager.GraphicsDevice.Viewport.Width - size.X) / 2, 515)
        size = New Vector2(GameManager.Sprites("MessageBox").Width, GameManager.Sprites("MessageBox").Height)
        Dim pos2 As New Vector2((GameManager.GraphicsDevice.Viewport.Width - size.X) / 2, 500)
        GameManager.SpriteBatch.Draw(GameManager.Sprites("MessageBox"), pos2, Color.White)
        GameManager.SpriteBatch.DrawString(GameManager.Font, Message, pos1, Color.White)
    End Sub

End Class